
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int N = 50010;
ll a[N];
struct SegTree {
  struct node {
    int l, r;
    ll mn, mx;
  } t[N * 4];
  void maintain(int p) {
    t[p].mn = min(t[p * 2].mn, t[p * 2 + 1].mn);
    t[p].mx = max(t[p * 2].mx, t[p * 2 + 1].mx);
  }
  void build(int p, int l, int r) {
    t[p].l = l, t[p].r = r;
    if (l == r) {
      t[p].mn = t[p].mx = a[l];
      return;
    }
    int mid = (l + r) / 2;
    build(p * 2, l, mid), build(p * 2 + 1, mid + 1, r);
    maintain(p);
  }
  int askmax(int p, int l, int r) {
    if (l <= t[p].l && r >= t[p].r) return t[p].mx;
    int mid = (t[p].l + t[p].r) / 2;
    int val = -1;
    if (l <= mid) val = max(val, askmax(p * 2, l, r));
    if (r > mid) val = max(val, askmax(p * 2 + 1, l, r));
    return val;
  }
  int askmin(int p, int l, int r) {
    if (l <= t[p].l && r >= t[p].r) return t[p].mn;
    int mid = (t[p].l + t[p].r) / 2;
    int val = 0x3f3f3f3f;
    if (l <= mid) val = min(val, askmin(p * 2, l, r));
    if (r > mid) val = min(val, askmin(p * 2 + 1, l, r));
    return val;
  }
} T;
int main() {
  // High rating and good luck!
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, q;
  while (cin >> n >> q) {
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    T.build(1, 1, n);

    while (q--) {
      int l, r;
      cin >> l >> r;
      cout << T.askmax(1, l, r) - T.askmin(1, l, r) << '\n';
    }
  }

  return 0;
}
